package com.example.yogurtsystem.controller;

import com.example.yogurtsystem.dto.ResultDTO;
import com.example.yogurtsystem.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Da
 * @date 2021/08/22
 **/

@RestController
@RequestMapping("/statistics/")
@CrossOrigin
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @PostMapping("{day}")
    public ResultDTO createStatisticsByDate(@PathVariable String day) {
        statisticsService.createStatisticsByDay(day);
        return ResultDTO.requestSuccess(statisticsService.selectStatistics(day));
    }

    @GetMapping("showchart/{begin}/{end}/{type}")
    public ResultDTO showChart(@PathVariable String begin,@PathVariable String end,@PathVariable
            String type){
        Map<String, Object> map = statisticsService.getChartData(begin, end, type);
        return ResultDTO.requestSuccess(map);
    }
}
